package com.mq.demo;

import com.mq.mqclient.Channel;
import com.mq.mqclient.Connection;
import com.mq.mqclient.ConnectionFactory;
import com.mq.mqserver.core.ExchangeType;

import java.io.IOException;

public class DemoProducer {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("启动⽣产者!");
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.56.1");
        factory.setPort(9090);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("testExchange11", ExchangeType.DIRECT, true,
                false, null);
        channel.queueDeclare("testQueue11", true, false, false, null);
        byte[] body = "hello".getBytes();
        boolean ok = channel.basicPublish("testExchange11", "testQueue11", null,
                body);
        System.out.println("投递消息完成! ok=" + ok);
        Thread.sleep(500);
        channel.close();
        connection.close();
    }
}
